local gallop = require "QGMainWindow"
local nl = require"luaNumeric"
local plot = require "Q2DViewerEx"
local FarfieldsPost = require "FarfieldsPost"
require "unity"



-----------------------------------------------------------------------------
--初始化参数
local RadomePost = FarfieldsPost:new({
	scan_angle = 0;
	trans = {};
	trans_range = 10;  --求透过率搜索区间
});
-----------------------------------------------------------------------------

-----------------------------------------------------------------------------
--求透过率
function RadomePost:calculate_transmission()
	local new_idx = {}
	for k,v in pairs(self.index) do
		new_idx[k] = v.label;
	end
	new_idx.phi = nil;
	new_idx.fields_types = {"Etotal"};	 
	local xx, yys = self:get_curves( "phi", new_idx );	
	
	self.trans.angle = nl.new_vector();
	self.trans.data = nl.new_vector();
	
	for k,v in pairs(yys) do
		local n = math.ceil( #v.data / 2);
		local v,idx = nl.max_and_index( v.data, n-self.trans_range,n+self.trans_range);
		self.trans.angle:add(xx[idx])
		self.trans.data:add(v);
	end	
end
-----------------------------------------------------------------------------

-----------------------------------------------------------------------------
--画远场
function RadomePost:plot_farfield ()
	if self.view ~= nil then
		 local new_idx = {}
		 for k,v in pairs(self.index) do
			 new_idx[k] = clone(v.label);
		 end
		 new_idx.phi = nil;	
		 new_idx.fields_types = {"Etotal"};	
		 self:plot_curves("phi", new_idx)
	end
end
-----------------------------------------------------------------------------

return RadomePost;


